package com.ds.infrastructure.hyperspace.console.model.request.containerconfig.configdata;

import com.ds.infrastructure.hyperspace.console.dto.configdata.NodesDTO;
import io.swagger.annotations.ApiModelProperty;
import lombok.Data;
import lombok.NoArgsConstructor;

import javax.validation.constraints.NotBlank;
import javax.validation.constraints.NotNull;
import javax.validation.constraints.Pattern;

/**
 * @author: yaozhendong
 * @create: 2019-09-23 09:52
 **/
@Data
@NoArgsConstructor
public class EntryEndpointForm {
    @NotBlank
    private String id;
    @NotBlank
    @ApiModelProperty(value = "协议名称:WEBSOCKET, HTTP, HTTP2C, HTTP2, HTTPS, WEBSOCKETS", example = "HTTP")
    @Pattern(regexp = "^WEBSOCKET|HTTP|HTTP2C|HTTP2|HTTPS|WEBSOCKETS$", message = "支持的协议（区取大小写）：WEBSOCKET|HTTP|HTTP2C|HTTP2|HTTPS|WEBSOCKETS")
    private String protocol;
    @NotNull
    private Integer port;
    @NotBlank
    private String ip;
    private String zone;

    public static NodesDTO toDTO(EntryEndpointForm form) {
        NodesDTO nodesDTO = new NodesDTO();
        nodesDTO.setId(form.getId());
        nodesDTO.setProtocol(form.getProtocol());
        nodesDTO.setHost(form.getIp());
        nodesDTO.setPort(form.getPort());
        nodesDTO.setZone(form.getZone());
        return nodesDTO;

    }


    public static EntryEndpointForm toVO(NodesDTO item) {
        EntryEndpointForm entryEndpointForm = new EntryEndpointForm();
        entryEndpointForm.setId(item.getId());
        entryEndpointForm.setProtocol(item.getProtocol());
        entryEndpointForm.setPort(item.getPort());
        entryEndpointForm.setIp(item.getHost());
        entryEndpointForm.setZone(item.getZone());
        return entryEndpointForm;
    }
}
